import Search from 'models/search';

export default class GoodsDefsSearch extends Search {
  goodsName = '';
  branchId = '';
  partnerId = '';
  status = '';

  propertyList = ['goodsName', 'branchId', 'partnerId', 'status'];

  constructor() {
    super();

    this.setOldData();
  }

  getObject(pagination, type = 'table') {
    let postData = {};

    if (type === 'table') {
      this.setPostData(postData, ['goodsName', 'status']);
    } else {
      this.setPostData(postData, ['goodsName', 'branchId', 'partnerId']);
      let status = this.status;
      if (status === '') {
        postData.status = [-1, 0, 1];
      } else {
        postData.status = [status];
      }
    }

    if (pagination !== undefined) {
      let {
        limit,
        page
      } = pagination.getObject();
      postData.limit = limit;
      postData.page = page;
    }
    return postData;
  }
}
